package com.example.shardingsphere.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.shardingsphere.demo.entity.Order;
import com.example.shardingsphere.demo.mapper.OrderMapper;
import com.example.shardingsphere.demo.service.IOrderService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Sunny
 * @since 2021-01-23
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Override
    public Order getOrder(String orderNo) {
        LambdaQueryWrapper<Order> query = Wrappers.lambdaQuery();
        query.eq(Order::getOrderNo, orderNo);
        return getOne(query);
    }

    @Override
    public List<Order> listOrders(Long userId, Integer timeType) {
        LambdaQueryWrapper<Order> query = Wrappers.lambdaQuery();
        query.eq(Order::getUserId, userId);
        query.eq(Order::getTimeType, timeType);
        return list(query);
    }

    @Override
    public boolean deleteOrder(String orderNo) {
        LambdaQueryWrapper<Order> query = Wrappers.lambdaQuery();
        query.eq(Order::getOrderNo, orderNo);
        return remove(query);
    }
}
